package com.hl.controller.Chat;

import com.hl.domain.ChatMessageDO;
import com.hl.domain.R;
import com.hl.service.ChatMessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private ChatMessageService chatMessageService;

    @GetMapping("/history")
    public R history(@RequestParam String me,
                     @RequestParam String peer,
                     @RequestParam(required = false) Long before,
                     @RequestParam(defaultValue = "50") Integer pageSize) {
        Date beforeDate = before == null ? new Date() : new Date(before);
        List<ChatMessageDO> list = chatMessageService.listHistory(me, peer, beforeDate, pageSize);
        return R.ok(list);
    }

    @PostMapping("/read")
    public R markRead(@RequestParam String me, @RequestParam String peer) {
        chatMessageService.markRead(me, peer);
        return R.ok();
    }
}

